﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.IO;

using CE.User;
using CE.Global;
using CE.Database;
using CE.CarInsurance;
using CE.Mail;

public partial class car_insurance_complete_quote : MyLanguageBasePage
{
    string _redirectUrl = "";
    protected override void InitializeCulture()
    {
        String selectedCulture = CE.Global.General.SetCulture();
        base.InitializeCulture();
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        Master.Page.Title = Resources.CarInsurance.ViewCompletedDetails;
        if (Session[CE.Global.General.UserId] != null && Session[CE.Global.General.UserTypeId] != null)
        {
            if (Convert.ToInt32(Session[CE.Global.General.UserTypeId]) !=
                Convert.ToInt32(CE.Global.CEUserType.Customer) && Convert.ToInt32(Session[CE.Global.General.UserTypeId]) !=
                Convert.ToInt32(CE.Global.CEUserType.Provider))
            {
                Response.Redirect("default.aspx");
            }
        }
        else
        {
            Response.Redirect("default.aspx");
        }

        if (Session["ViewCIResultId"] == null)
        {
            Response.Redirect("~/user/saved-quotes");
        }

        if (!IsPostBack)
        {
            //txtExEmail.Text = Session[CE.Global.General.UserEmail].ToString();

            if (Session["ViewCIResultId"] != null)      // || Page.Request.Params["ResultId"] != null)
            {
                Int64 _tempResultId = 0;
                Int64 _carId = 0;
                if (Int64.TryParse(Convert.ToString(Session["ViewCIResultId"]), out _tempResultId))       //(Int64.TryParse(Page.Request.Params["ResultId"], out _tempResultId))
                {
                    _carId = CheckCompleteStatus(_tempResultId);

                    if (_carId > 0)
                    {
                        ShowDetails(_carId);
                    }
                    else
                    {
                        Response.Redirect("~/user/saved-quotes");
                    }
                }
                else
                {
                    Response.Redirect("~/user/saved-quotes");
                }
            }
        }

    }

    private Int64 CheckCompleteStatus(Int64 _resultId)
    {
        UserResultHistory _result = new UserResultHistory();
        UserResultHistoryDB _resultdb = new UserResultHistoryDB();
        Int64 _carId = 0;
        Int64 CustomerId = 0;
        if (Session[CE.Global.General.UserId] != null)
        {
            CustomerId = Convert.ToInt64(Session[CE.Global.General.UserId].ToString());
        }
        _result = _resultdb.GetResultHistory(Convert.ToInt64(Session[General.UserId].ToString()), _resultId);
        if (_result != null && _result.IsComplete)
        {
            _carId = _result.ID1;
        }
        else
        {
            DataSet _ds = GetCarDetails(_result.ID1, CustomerId);
            if (_ds != null && _ds.Tables.Count > 2 && _ds.Tables[2].Rows.Count > 0)
            {
                _carId = _result.ID1;
            }
        }

        return _carId;
    }

    private void ShowDetails(Int64 _carId)
    {
        Int64 CustomerId = Convert.ToInt64(Session[CE.Global.General.UserId].ToString());
        //hidGetStep.Value = "1";
        DataSet _dsOffline = new DataSet();
        _dsOffline = GetCarDetails(_carId, CustomerId);
        if (_dsOffline != null && _dsOffline.Tables.Count > 2 && _dsOffline.Tables[2].Rows.Count > 0)
        {
            //hidGetStep.Value = "2";
            ShowNonGGDetails(_dsOffline);
            return;
        }
        Int64 _refCEUserId = Convert.ToInt64(Convert.ToInt64(Session[General.UserId].ToString()));
        string _refNo = "";
        CarDetailTH _cardetailth = new CarDetailTH();
        CarDetailTHDB _cardetailthdb = new CarDetailTHDB();
        CE.Database.MyDatabase _db = new CE.Database.MyDatabase();
        DataSet _dsInsurance = new DataSet();

        Int64 _companyId = 0;

        System.Data.DataTable _dtSeletectItem = new System.Data.DataTable("SelectedResultItem");
        _dtSeletectItem = _db.GetDataTable("Select * from tblCarInsuranceSelectItemTH WHERE CarId = " + _carId.ToString());
        if (_dtSeletectItem != null && _dtSeletectItem.Rows.Count > 0)
        {
            _companyId = Convert.ToInt64(_dtSeletectItem.Rows[0]["ProviderCompanyId"].ToString());
            lblAnnualPremium.Text = "$ " + Convert.ToSingle(_dtSeletectItem.Rows[0]["AnnualPremium"].ToString()).ToString("#.00");
        }
        CarInsuranceCompletedItemDB _carinsurancecompleteditemdb = new CarInsuranceCompletedItemDB();
        _dsInsurance = _carinsurancecompleteditemdb.GetCarInsuranceCompletedItem(_carId, _companyId);
        if (_dsInsurance != null && _dsInsurance.Tables[0].Rows.Count > 0)
        {
            //lblGender.Text = _dsInsurance.Tables[0].Rows[0]["Gender"].ToString() == "Male" ? Resources.CarInsurance.Male : Resources.CarInsurance.Female;
            //lblDOB.Text = Convert.ToDateTime(_dsInsurance.Tables[0].Rows[0]["DOB"]).ToString("dd-MMM-yyyy");
            //if (CE.Global.General.SetCulture() == "th-TH")
            //{
            //    lblOccupation.Text = _dsInsurance.Tables[0].Rows[0]["THOccupation"].ToString();
            //}
            //else
            //{
            //    lblOccupation.Text = _dsInsurance.Tables[0].Rows[0]["ENOccupation"].ToString();
            //}

            switch (_dsInsurance.Tables[0].Rows[0]["InsuranceType"].ToString())
            {
                case "Class 1":
                    lblInsuranceType.Text = Resources.CarInsurance.Insurance_ClassOne;
                    break;
                case "Class 1 (Low Cost)":
                    lblInsuranceType.Text = Resources.CarInsurance.Insurance_ClassOneLowCost;
                    break;
                case "Class 2+":
                    lblInsuranceType.Text = Resources.CarInsurance.Insurance_ClassTwoPlus;
                    break;
                case "Class 3+":
                    lblInsuranceType.Text = Resources.CarInsurance.Insurance_ClassThreePlus;
                    break;
                case "Class 3":
                    lblInsuranceType.Text = Resources.CarInsurance.Insurance_ClassThree;
                    break;
            }

            hplViewGarage.NavigateUrl = SetViewGarageUrl(_companyId.ToString());
            lblGarageType.Text = _dsInsurance.Tables[0].Rows[0]["GarageType"].ToString() == "Authorized" ? Resources.CarInsurance.Garage_Authorized : Resources.CarInsurance.Garage_Dealer;
            lblCarModelYear.Text = _dsInsurance.Tables[0].Rows[0]["CarModelYear"].ToString();
            lblCarMakeModel.Text = _dsInsurance.Tables[0].Rows[0]["MakeModelDesc"].ToString();
            lblVehicleType.Text = _dsInsurance.Tables[0].Rows[0]["VehicleType"].ToString() == "Private Use" ? Resources.CarInsurance.VehicleType_Private : Resources.CarInsurance.VehicleType_Commercial;
            lblRedPlate.Text = _dsInsurance.Tables[0].Rows[0]["RedPlate"].ToString();
            lblSumInsured.Text = Convert.ToSingle(_dsInsurance.Tables[0].Rows[0]["SumInsured"]).ToString("#,###") + " " + Resources.CarInsurance.Baht;
            lblProvinceofRegistration.Text = _dsInsurance.Tables[0].Rows[0]["ProvinceRegistration"].ToString() == "Bangkok Metro Area" ? Resources.CarInsurance.Province_BKK : Resources.CarInsurance.Province_UPC;
            lblAnyClaim.Text = _dsInsurance.Tables[0].Rows[0]["AnyClaim"].ToString() == "Yes" ? Resources.CarInsurance.Option_YesHave : Resources.CarInsurance.Option_NoHave;
            lblNCB.Text = _dsInsurance.Tables[0].Rows[0]["NCB"].ToString() + "%";
            lblAddDriver.Text = _dsInsurance.Tables[0].Rows[0]["Driver"].ToString() == "Yes" ? Resources.CarInsurance.Option_YesSpecify : Resources.CarInsurance.Option_NoSpecify;
            if (_dsInsurance.Tables[0].Rows[0]["CommenceDate"] != DBNull.Value)
            {
                lblCoverCommenceDate.Text = Convert.ToDateTime(_dsInsurance.Tables[0].Rows[0]["CommenceDate"]).ToString("dd-MMM-yyyy");
            }

            if (_dsInsurance.Tables.Count > 1)
            {
                if (_dsInsurance.Tables[1].Rows.Count > 0)
                {
                    object moddate = _db.ExecuteScalarSqlStatement("SELECT Modifieddate FROM tblCarPolicy WHERE CECarId = " + _carId.ToString());
                    if (moddate != null)
                        //hidModDate.Value = Convert.ToDateTime(moddate).ToString("dd-MMM-yyyy", new System.Globalization.CultureInfo("en-US"));

                    if (_dsInsurance.Tables[1].Rows[0]["CoverTypeDesc"].ToString() != "GluayGluay.com Special")
                    {
                        lblInsurer.Text = GetInsurer(_companyId);
                        lblPackage.Text = _dsInsurance.Tables[1].Rows[0]["CoverTypeDesc"].ToString();
                    }
                    else
                    {
                        lblInsurance.Text = Resources.ProposalForm.Package;
                        lblInsurer.Text = _dsInsurance.Tables[1].Rows[0]["CoverTypeDesc"].ToString();
                        lblPackageName.Text = Resources.ProposalForm.PackageCondition;
                        lblPackage.Text = Resources.CarInsuranceResultPage.SpecialNCB;

                        hplViewGarage.Visible = false;
                    }
                    lblAnnualPremium.Text = Convert.ToSingle(_dsInsurance.Tables[1].Rows[0]["AnnualPremium"]).ToString("#,###.00") + " " + Resources.CarInsurance.Baht;
                    lblCTPL.Text = _dsInsurance.Tables[1].Rows[0]["CTPL"].ToString() == "Yes" ? Resources.CarInsurance.Option_Yes : Resources.CarInsurance.Option_No;
                    if (_dsInsurance.Tables[1].Rows[0]["CTPL"].ToString() != "Yes")
                        divCTPLAmount.Style.Add("display", "none");
                    lblCTPLAmount.Text = Convert.ToSingle(_dsInsurance.Tables[1].Rows[0]["CTPLAmount"]).ToString("#.00") + " " + Resources.CarInsurance.Baht;


                    lblName.Text = _dsInsurance.Tables[1].Rows[0]["Name"].ToString();
                    lblIdentificationNo.Text = "";
                    if (_dsInsurance.Tables[1].Rows[0]["IdentificationNo"] != null)
                    {
                        lblIdentificationNo.Text = _dsInsurance.Tables[1].Rows[0]["IdentificationNo"].ToString();
                    }
                    lblContactNo.Text = String.Format("{0:0##-###-####}", Convert.ToInt32(_dsInsurance.Tables[1].Rows[0]["ContactNo"]));
                    lblVehicleNo.Text = _dsInsurance.Tables[1].Rows[0]["VehicleNo"].ToString();
                    lblEngineNo.Text = _dsInsurance.Tables[1].Rows[0]["EngineNo"].ToString();
                    lblChassisNo.Text = _dsInsurance.Tables[1].Rows[0]["ChassisNo"].ToString();
                    lblVehicleColor.Text = _dsInsurance.Tables[1].Rows[0]["VehicleColor"].ToString();
                    lblVehicleProvince.Text = _dsInsurance.Tables[1].Rows[0]["VehicleProvince"].ToString();
                    if (_dsInsurance.Tables[1].Rows[0]["PolicyStartDate"] != DBNull.Value)
                    {
                        lblPolicyStartDate.Text = Convert.ToDateTime(_dsInsurance.Tables[1].Rows[0]["PolicyStartDate"]).ToString("dd-MMM-yyyy");
                        lblPolicyEndDate.Text = Convert.ToDateTime(_dsInsurance.Tables[1].Rows[0]["PolicyStartDate"]).AddYears(1).ToString("dd-MMM-yyyy");
                    }
                    _refNo = _dsInsurance.Tables[1].Rows[0]["QuoteRefNo"].ToString();

                    //Sakthi on 12 Jan 2012  -- Start
                    //switch (_dsInsurance.Tables[1].Rows[0]["PaymentType"].ToString())
                    //{
                    //    case "CreditCard":
                    //        lblPaymentType.Text = Resources.ProposalForm.CreditCard;
                    //        break;
                    //    case "Bank In":
                    //        lblPaymentType.Text = Resources.ProposalForm.BankIn;
                    //        break;
                    //}
                    //switch (_dsInsurance.Tables[1].Rows[0]["PaymentStatus"].ToString())
                    //{
                    //    case "True":
                    //        lblPaymentStatus.Text = Resources.ProposalForm.Yes;
                    //        break;
                    //    case "False":
                    //        lblPaymentStatus.Text = Resources.ProposalForm.No;
                    //        break;
                    //}
                    //if (_dsInsurance.Tables[1].Rows[0]["PaymentType"].ToString() == "CreditCard")
                    //{
                    //    switch (_dsInsurance.Tables[1].Rows[0]["PaymentCode"].ToString())
                    //    {
                    //        case "0":
                    //            lblPaymentStatus.Text += " - " + Resources.ProposalForm.Fail;
                    //            break;
                    //        case "1":
                    //            lblPaymentStatus.Text += " - " + Resources.ProposalForm.Success;
                    //            break;
                    //        case "2":
                    //            lblPaymentStatus.Text += " - " + Resources.ProposalForm.Cancel;
                    //            break;
                    //    }
                    //}
                    //Sakthi on 12 Jan 2012  -- End
                }
            }

            lblQuoteTitle.Text = Resources.CarInsurance.QuoteRefNo + " : " + _refNo + " - " + Resources.CarInsurance.CarInsuranceList + " " + lblCarMakeModel.Text;
            //hidRefNo.Value = _refNo;
        }
    }

    private void ShowNonGGDetails(DataSet DsNonGG)
    {
        if (DsNonGG != null && DsNonGG.Tables.Count > 2 && DsNonGG.Tables[2].Rows.Count > 0)
        {
            Int64 _refCEUserId = Convert.ToInt64(Convert.ToInt64(Session[General.UserId].ToString()));
            string _refNo = "";
            Int64 _companyId = Convert.ToInt64(DsNonGG.Tables[2].Rows[0]["ProviderCompanyId"].ToString());
            lblAnnualPremium.Text = "$ " + Convert.ToSingle(DsNonGG.Tables[2].Rows[0]["TotalCollectedPremium"].ToString()).ToString("#.00");

            //lblGender.Text = DsNonGG.Tables[2].Rows[0]["Gender"].ToString() == "M" ? Resources.CarInsurance.Male : Resources.CarInsurance.Female;
            //lblDOB.Text = Convert.ToDateTime(DsNonGG.Tables[0].Rows[0]["DOB"]).ToString("dd-MMM-yyyy");
            //if (CE.Global.General.SetCulture() == "th-TH")
            //{
            //    lblOccupation.Text = DsNonGG.Tables[2].Rows[0]["OccupationTH"].ToString();
            //}
            //else
            //{
            //    lblOccupation.Text = DsNonGG.Tables[2].Rows[0]["OccupationEN"].ToString();
            //}

            switch (DsNonGG.Tables[2].Rows[0]["InsuranceType"].ToString())
            {
                case "10":
                    lblInsuranceType.Text = Resources.CarInsurance.Insurance_ClassOne;
                    break;
                case "11":
                    lblInsuranceType.Text = Resources.CarInsurance.Insurance_ClassOneLowCost;
                    break;
                case "21":
                    lblInsuranceType.Text = Resources.CarInsurance.Insurance_ClassTwoPlus;
                    break;
                case "31":
                    lblInsuranceType.Text = Resources.CarInsurance.Insurance_ClassThreePlus;
                    break;
                case "30":
                    lblInsuranceType.Text = Resources.CarInsurance.Insurance_ClassThree;
                    break;
            }

            hplViewGarage.NavigateUrl = SetViewGarageUrl(_companyId.ToString());
            lblGarageType.Text = DsNonGG.Tables[2].Rows[0]["GarageType"].ToString() == "1" ? Resources.CarInsurance.Garage_Authorized : Resources.CarInsurance.Garage_Dealer;
            lblCarModelYear.Text = DsNonGG.Tables[2].Rows[0]["CarYear"].ToString();
            lblCarMakeModel.Text = DsNonGG.Tables[2].Rows[0]["CarModel"].ToString();
            lblVehicleType.Text = DsNonGG.Tables[2].Rows[0]["VehicleType"].ToString() == "110" ? Resources.CarInsurance.VehicleType_Private : Resources.CarInsurance.VehicleType_Commercial;
            lblRedPlate.Text = DsNonGG.Tables[2].Rows[0]["CarYear"].ToString();
            lblSumInsured.Text = Convert.ToSingle(DsNonGG.Tables[0].Rows[0]["SumInsured"]).ToString("#,###") + " " + Resources.CarInsurance.Baht;
            lblProvinceofRegistration.Text = DsNonGG.Tables[2].Rows[0]["CarPlateProvince"].ToString();
            lblAnyClaim.Text = Resources.CarInsurance.Option_NoHave;
            if (DsNonGG.Tables[2].Rows[0]["IsClaim"] != DBNull.Value && DsNonGG.Tables[2].Rows[0]["IsClaim"].ToString() != string.Empty)
            {
                lblAnyClaim.Text = DsNonGG.Tables[2].Rows[0]["IsClaim"].ToString() == "1" ? Resources.CarInsurance.Option_YesHave : Resources.CarInsurance.Option_NoHave;
            }
            lblNCB.Text = DsNonGG.Tables[2].Rows[0]["NCB"].ToString() + "%";
            lblAddDriver.Text = DsNonGG.Tables[2].Rows[0]["NoOfDriver"].ToString() != "0" ? Resources.CarInsurance.Option_YesSpecify : Resources.CarInsurance.Option_NoSpecify;
            lblCoverCommenceDate.Text = Convert.ToDateTime(DsNonGG.Tables[2].Rows[0]["CoverageStart"]).ToString("dd-MMM-yyyy");

            lblInsurer.Text = GetInsurer(Int32.Parse(DsNonGG.Tables[2].Rows[0]["ProviderCompanyId"].ToString())); //DsNonGG.Tables[2].Rows[0]["CurrentInsurer"].ToString();
            lblAnnualPremium.Text = Convert.ToSingle(DsNonGG.Tables[2].Rows[0]["TotalCollectedPremium"]).ToString("#,###.00") + " " + Resources.CarInsurance.Baht;
            lblCTPL.Text = DsNonGG.Tables[2].Rows[0]["IsCTPL"].ToString() == "True" ? Resources.CarInsurance.Option_Yes : Resources.CarInsurance.Option_No;
            if (DsNonGG.Tables[2].Rows[0]["IsCTPL"].ToString() != "True")
                divCTPLAmount.Style.Add("display", "none");
            lblCTPLAmount.Text = Convert.ToSingle(DsNonGG.Tables[2].Rows[0]["CTPL"]).ToString("#.00") + " " + Resources.CarInsurance.Baht;
            lblPackage.Text = DsNonGG.Tables[2].Rows[0]["Package"].ToString();

            lblName.Text = DsNonGG.Tables[2].Rows[0]["Name"].ToString();
            lblIdentificationNo.Text = "N/A";

            lblContactNo.Text = String.Format("{0:0##-###-####}", Convert.ToInt32(DsNonGG.Tables[2].Rows[0]["ContactNo"]));
            lblVehicleNo.Text = DsNonGG.Tables[2].Rows[0]["CarPlate"].ToString();
            lblEngineNo.Text = DsNonGG.Tables[2].Rows[0]["EngineNumber"].ToString();
            lblChassisNo.Text = DsNonGG.Tables[2].Rows[0]["ChassisNumber"].ToString();
            lblVehicleProvince.Text = DsNonGG.Tables[2].Rows[0]["CarPlateProvince"].ToString();
            lblPolicyStartDate.Text = Convert.ToDateTime(DsNonGG.Tables[2].Rows[0]["CoverageStart"]).ToString("dd-MMM-yyyy"); //CTPLStart
            lblPolicyEndDate.Text = Convert.ToDateTime(DsNonGG.Tables[2].Rows[0]["CoverageStart"]).AddYears(1).ToString("dd-MMM-yyyy");
            //hidModDate.Value = Convert.ToDateTime(DsNonGG.Tables[2].Rows[0]["Modifieddate"]).ToString("dd-MMM-yyyy", new System.Globalization.CultureInfo("en-US"));
            _refNo = DsNonGG.Tables[2].Rows[0]["QuoteRefNo"].ToString();

            lblPolicyNumber.Text = GetPolicyNumber(Int32.Parse(DsNonGG.Tables[2].Rows[0]["RefCEUserId"].ToString()),
                    Int32.Parse(DsNonGG.Tables[2].Rows[0]["CECarId"].ToString()),
                    DsNonGG.Tables[2].Rows[0]["QuoteRefNo"].ToString());

            if (DsNonGG.Tables[3].Rows.Count > 0)
            {
                divFirstDriver.Style.Add("display", "");
                lblDriverFirst.Text = DsNonGG.Tables[3].Rows[0]["FullName"].ToString();
            }
            if (DsNonGG.Tables[3].Rows.Count > 1)
            {
                divSecondDriver.Style.Add("display", "");
                lblDriverTwo.Text = DsNonGG.Tables[3].Rows[1]["FullName"].ToString();
            }

            //lblPaymentType.Text = "N/A";
            //switch (DsNonGG.Tables[2].Rows[0]["PaymentStatus"].ToString())
            //{
            //    case "1":
            //        lblPaymentStatus.Text = Resources.ProposalForm.Yes;
            //        break;
            //    case "0":
            //        lblPaymentStatus.Text = Resources.ProposalForm.No;
            //        break;
            //}
            lblQuoteTitle.Text = Resources.CarInsurance.QuoteRefNo + " : " + _refNo + " - " + Resources.CarInsurance.CarInsuranceList + " " + lblCarMakeModel.Text;
            //hidRefNo.Value = _refNo;
        }
    }

    protected void btnBack_Click(object sender, EventArgs e)
    {
        _redirectUrl = CE.Global.General.GetUrl("~/user/saved-quotes", Page);
        Response.Redirect(_redirectUrl);
    }

    public string GetInsurer(Int64 CompanyId)
    {
        MyDatabase _db = new MyDatabase();
        object CompanyName;
        if (CE.Global.General.SetCulture() == "th-TH")
        {
            CompanyName = _db.ExecuteScalarSqlStatement("SELECT THCompanyNameDescription FROM tblProviderCompany WHERE ProviderCompanyId = " + CompanyId.ToString());
        }
        else
        {
            CompanyName = _db.ExecuteScalarSqlStatement("SELECT CompanyNameDescription FROM tblProviderCompany WHERE ProviderCompanyId = " + CompanyId.ToString());
        }

        string _Insurer = "";
        if (CompanyName != null)
        {
            _Insurer = CompanyName.ToString();
        }
        return _Insurer;
    }

    public string GetPolicyNumber(Int32 RefCEUserId, Int32 CECarId, string QuoteRefNo)
    {
        MyDatabase _db = new MyDatabase();
        object PolicyNumber;
        PolicyNumber = _db.ExecuteScalarSqlStatement("SELECT Remarks FROM tblNonGGTransaction WHERE TransactionTypeID = 400 AND RefCEUserId = " + RefCEUserId.ToString() + " AND CECarId = " + CECarId.ToString() + " AND QuoteRefNo = '" + QuoteRefNo + "' Order By ModifiedDate DESC");

        string _PolicyNumber = "";
        if (PolicyNumber != null)
        {
            _PolicyNumber = PolicyNumber.ToString();
        }

        return _PolicyNumber;
    }

    private string SetViewGarageUrl(string _companyId)
    {
        string url = string.Empty;
        if (_companyId == "11")
        {
            // "Allianz C.P";
            if (HttpContext.Current.Session["Language"].ToString() == "th-TH")
            {
                url = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.AllianceWorkshopTH");
            }
            else
            {
                url = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.AllianceWorkshopEN");
            }

        }
        else if (_companyId == "12")
        {
            //lblPromo.Text = "MSIG";
            if (HttpContext.Current.Session["Language"].ToString() == "th-TH")
            {
                url = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.MSIGWorkshopTH");
            }
            else
            {
                url = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.MSIGWorkshopEN");
            }
        }
        else if (_companyId == "16")
        {
            //lblPromo.Text = "AXA";
            if (HttpContext.Current.Session["Language"].ToString() == "th-TH")
            {
                url = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.AXAWorkshopTH");
            }
            else
            {
                url = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.AXAWorkshopEN");
            }
        }
        else if (_companyId == "29")
        {
            //lblPromo.Text = "LMG Insurance";
            if (HttpContext.Current.Session["Language"].ToString() == "th-TH")
            {
                url = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.LMGWorkshopTH");
            }
            else
            {
                url = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.LMGWorkshopEN");
            }
        }
        else if (_companyId == "31")
        {
            //lblPromo.Text = "Chartis";
            if (HttpContext.Current.Session["Language"].ToString() == "th-TH")
            {
                url = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.ChartisWorkshopTH");
            }
            else
            {
                url = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.ChartisWorkshopEN");
            }
        }
        else if (_companyId == "32")
        {
            //lblPromo.Text = "Bangkok Insurance";
            if (HttpContext.Current.Session["Language"].ToString() == "th-TH")
            {
                url = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.BKIWorkshopTH");
            }
            else
            {
                url = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.BKIWorkshopEN");
            }
        }
        else if (_companyId == "33")
        {
            //lblPromo.Text = "MTI Insurance";
            if (HttpContext.Current.Session["Language"].ToString() == "th-TH")
            {
                url = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.MTIWorkshopTH");
            }
            else
            {
                url = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.MTIWorkshopTH");
            }
        }
        else if (_companyId == "35")
        {

            if (HttpContext.Current.Session["Language"].ToString() == "th-TH")
            {
                url = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.KPIWorkshopTH");
            }
            else
            {
                url = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.KPIWorkshopTH");
            }
        }
        else if (_companyId == "39")
        {

            if (HttpContext.Current.Session["Language"].ToString() == "th-TH")
            {
                url = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.MittareWorkshopTH");
            }
            else
            {
                url = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.MittareWorkshopEN");
            }
        }
        else if (_companyId == "41")
        {
            //lblPromo.Text = KSK "Kurnia Insurance";  
            if (HttpContext.Current.Session["Language"].ToString() == "th-TH")
            {
                url = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.KSKWorkShopTH");
            }
            else
            {
                url = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.KSKWorkShopTH");
            }
        }
        else if (_companyId == "43")
        {
            //lblPromo.Text = "Syn Mun Kong Insurance";
            if (HttpContext.Current.Session["Language"].ToString() == "th-TH")
            {
                url = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.SMKWorkShopTH");
            }
            else
            {
                url = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.SMKWorkShopTH");
            }
        }
        else if (_companyId == "45")
        {
            //lblPromo.Text = "Viriyah Insurance";
            if (HttpContext.Current.Session["Language"].ToString() == "th-TH")
            {
                url = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.ViriyahWorkShopTH");
            }
            else
            {
                url = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.ViriyahWorkShopTH");
            }
        }
        else if (_companyId == "46")
        {
            //lblPromo.Text = "TMS Insurance";
            if (HttpContext.Current.Session["Language"].ToString() == "th-TH")
            {
                url = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.TokioWorkShopTH");
            }
            else
            {
                url = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.TokioWorkShopEH");
            }
        }
        else if (_companyId == "50")
        {
            //lblPromo.Text = "TMS Insurance";
            if (HttpContext.Current.Session["Language"].ToString() == "th-TH")
            {
                url = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.SCSMGWorkshopTH");
            }
            else
            {
                url = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.SCSMGWorkshopEN");
            }
        }
        else if (_companyId == "58")
        {
            //lblPromo.Text = "TMS Insurance";
            if (HttpContext.Current.Session["Language"].ToString() == "th-TH")
            {
                url = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.ThaivivatWorkShopTH");
            }
            else
            {
                url = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.ThaivivatWorkShopEN");
            }
        }
        else if (_companyId == "65")
        {
            //lblPromo.Text = "Dhipaya Insurance";
            if (HttpContext.Current.Session["Language"].ToString() == "th-TH")
            {
                url = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.DhipayaWorkShopTH");
            }
            else
            {
                url = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.DhipayaWorkShopEN");
            }
        }
        else if (_companyId == "66")
        {
            //lblPromo.Text = "Thaipaiboon Insurance";
            if (HttpContext.Current.Session["Language"].ToString() == "th-TH")
            {
                url = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.ThaipaiboonWorkShopTH");
            }
            else
            {
                url = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.ThaipaiboonWorkShopEN");
            }
        }
        else if (_companyId == "67")
        {
            //lblPromo.Text = "Deves Insurance";
            if (HttpContext.Current.Session["Language"].ToString() == "th-TH")
            {
                url = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.DevesWorkshopTH");
            }
            else
            {
                url = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.DevesWorkshopEN");
            }
        }
        else if (_companyId == "68")
        {
            //lblPromo.Text = "Thaisri Insurance";
            if (HttpContext.Current.Session["Language"].ToString() == "th-TH")
            {
                url = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.ThaisriWorkshopTH");
            }
            else
            {
                url = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.ThaisriWorkshopEN");
            }
        }
        else if (_companyId == "69")
        {
            //lblPromo.Text = "Thaisri Insurance";
            if (HttpContext.Current.Session["Language"].ToString() == "th-TH")
            {
                url = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.AssetWorkshopTH");
            }
            else
            {
                url = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.AssetWorkshopEN");
            }
        }
        return url;
    }

    public DataSet GetCarDetails(Int64 CarId, Int64 CustomerId)
    {
        MyDatabase _db = new MyDatabase();
        string _spName = "[sprocCXCRMNONGGPackageCarDetailsSelectedItemByCarId]";

        SortedList _spara = new SortedList();
        _spara.Add("@CarId", CarId);
        _spara.Add("@CustomerId", CustomerId);

        DataSet _ds = _db.GetDataSet(_spName, _spara);

        return _ds;
    }

}
